(function(doc,win){
    var htmlFont = function(){
        var docEl = doc.documentElement,l = docEl.clientWidth,f;
        f = l / 18;
        l > 720 ? docEl.style.fontSize = 40 + "px": docEl.style.fontSize = f + "px";
    };
    htmlFont();
    win.addEventListener("resize", htmlFont, false);
})(document,window);


$.fn.disabled = function(s){
    /*s={flag:true|false, img:true|false}*/
    s = $.extend({flag:true,
                 img:false,
                 img2:false,
                 fixed:false},s);

    var _self = this;
    var _id = _self.attr('id');
    if(s.flag){
        if (s.fixed) {
            _self.css({'position':'relative','z-index':1}).append('<i style="position:absolute;left:0;top:0;filter:alpha(opacity=40);opacity:.4;width:'+$(_self).width()+'px;height:'+$(_self).height()+'px;background:#000 url(/site_media/images/public/common/loading16.gif) center no-repeat;" class="disabledmask"></i>');
            $(".disabledmask").click(function(e){e.preventDefault();e.stopPropagation();return false;})
        }else{
            if(s.img) {
                var loading_html = '<div id="'+_id+'_loading_img" style="background:#000 url(/site_media/images/public/common/loading16.gif) center no-repeat; filter:alpha(opacity=40); opacity: .40; position:absolute; z-index:99; ';
                loading_html += 'width:'+$(_self).width()+'px;padding-right:'+$(_self).css("padding-right")+';padding-left:'+$(_self).css("padding-left")+'; height:'+$(_self).height()+'px; left:'+$(_self).offset().left+'px; top:'+$(_self).offset().top+'px;'
                loading_html += '"></div>';
                $("body").append(loading_html);
            }
            if(s.img2){
                $("#"+ _id).after("&nbsp;<img id='"+ _id +"_img2' src='/site_media/images/public/common/loading16.gif' />");
            }
            else{
                $("#"+ _id +"_img2").remove();
            }
        }
        _self.prop('disabled', true);
    }else{
        $("#"+ _id +"_loading_img").remove();
        $("#"+ _id +"_img2").remove();
        _self.prop('disabled', false);
        _self.find('.disabledmask').length && _self.find('.disabledmask').remove() && $(".disabledmask").unbind();
    }
    return this;
};
// login logout
//退出
//返回数据{'state':0,'msg':u'账号或密码错误',"url":""} state = 1正常退出 msg ：提示。url：登陆成功后默认跳转地址
$.logout = function(s){
    s = $.extend({domain_url:"",func:function(){location.reload();}},s);
    $.getJSON(s.domain_url+"/common/passport/logout_server/?callback=?",function(_json){
        //$.getJSON(_json.tbkt_url+"/common/sso/logout/?callback=?",function(json){
        if($.isFunction(s.func))
             s.func(_json);
        //});
    });
};

//注销成功回调函数
function logoutCallBack(json){
    if(json.state == 1){
        location.href = json.url+'?wap=1';
    }else{
        dialog.alert(json.msg);
    }
}
$(function(){
    $('#logout').on('click',function(e){
        window.onbeforeunload = null;
        var domain = location.host;
        $.logout({domain:domain, func:logoutCallBack});
    });
})
// 屏幕高度
function initHeight(){
    var swh=0;
    if(window.innerHeight){
        swh=window.innerHeight;
    }else if(document.body&&document.body.clientHeight){
        swh=document.body.clientHeight;
    }
    if(document.documentElement&&document.documentElement.clientHeight){
        swh=document.documentElement.clientHeight;
    }
    $('.main').css('height',swh);
}
$(function(){
    initHeight();
    window.addEventListener("resize", initHeight, false);
})
